package com.zsw.customer2c.controller;

import com.zsw.customer2c.service.testService;
import com.zsw.customer2c.service.testServiceProducer2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 使用feign 微服务之间的通信
 */
@RestController
public class testController {

    //注入外部接口
    @Autowired
    testService testService;

    @Autowired
    testServiceProducer2 testServiceProducer2;

    private String message="当前的消费端是customer2feign,启用负载均衡，端口号：7003";


    //===========测试fallback

    @RequestMapping("1/hi/{id}")
    public String hi1(@PathVariable String id){
        System.out.println("这个是从另一个服务调用的，哈哈，服务名是serviceproducer1");
        return message+">>>"+testService.hi(id);
    }

    @GetMapping("1/client")
    public String test1(){
        System.out.println("这个是从另一个服务调用的，哈哈，服务名是serviceproducer1");
        return message+">>>"+testService.test();
    }

    @GetMapping(value = "1/fallback")
    public String expectFallback1(){

        System.out.println("服务生产者,服务名是serviceproducer1没有这个请求，期望他会熔断");
        return message+">>>"+testService.expectFallback();
    }


    //===========测试fallbackFactory，带有熔断异常信息

    @GetMapping("2/hi/{id}")
    public String hi2(@PathVariable String id){
        System.out.println("这个是从另一个服务调用的，哈哈，服务名是serviceproducer2");
        return message+">>>"+testServiceProducer2.hi(id);
    }

    @GetMapping("2/client")
    public String test2(){
        System.out.println("这个是从另一个服务调用的，哈哈，服务名是serviceproducer2");
        return message+">>>"+testServiceProducer2.test();
    }

    @GetMapping(value = "2/fallback")
    public String expectFallback2(){

        System.out.println("服务生产者,服务名是serviceproducer2没有这个请求，期望他会熔断");
        return message+">>>"+testServiceProducer2.expectFallback();
    }
}
